class RegularUtils {
  static final _onlyNumberRe = r"^[0-9]+$";
  static final _htmlPop = r"^http";
  static final _phoneRe = r"(^1\d{10}$)";
  ///社会信用码规则
  static final _socialCode = r"(^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$)";
  static final _idCardRe = r"(\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)";
  static final String _chineseRe = r"[\u4e00-\u9fa5]";
  static final String _routeRe = r"#kuaibu.*#";

  static final _removeHtmlLabel = r">.*<";

  static final _richText = r"[<p|<img|h]+";
  static final _route = r"[a-z]+://[a-z|_]+/?";
  static bool onlyNumber(String text) {
    return RegExp(_onlyNumberRe).hasMatch(text);
  }
  static bool isRoute(String text){
    return RegExp(_route).hasMatch(text);
  }
  static bool phone(String text) {
    bool matched = RegExp(_phoneRe).hasMatch(text);
    return matched;
  }
  static bool socialCode(String text) {
    bool matched = RegExp(_socialCode).hasMatch(text);
    return matched;
  }
  static bool idCard(String text) {
    bool matched = RegExp(_idCardRe).hasMatch(text);
    return matched;
  }
  static bool html(String text) {
    return RegExp(_htmlPop).hasMatch(text);
  }
  static bool richText(String text) {
    return RegExp(_richText).hasMatch(text);
  }
  // 邮箱判断
  static bool isEmail(String input) {
    String regexEmail = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}\$";
    if (input == null || input.isEmpty) return false;
    return new RegExp(regexEmail).hasMatch(input);
  }

  static String route(String text){
    List<RegExpMatch> route = RegExp(_routeRe).allMatches(text).toList();
    String name = route.first.group(0);
    name = name.replaceAll("#","");
    return name;
  }
  static String removeLabel(String text){
    List<RegExpMatch> route = RegExp(_removeHtmlLabel).allMatches(text).toList();
    List<String> data = route.map((e) => e.group(0).substring(1,e.end-e.start - 1)).toList();
    return data.join("");
  }
}
